/***
 * 类(Class)
 *
 * 访问修饰符
 */

export {}

class Person {
  // 默认，公共成员
  public name = ''
  // 私有成员
  private age = 0
  // 受保护的成员，只允许在此类中访问该成员，可被继承
  protected gender: boolean = false

  constructor(name: string, age: number) {
    this.name = name
    this.age = age
  }
  sayHi(msg: string): void {
    console.log(this.name)
  }
}

class Student extends Person {
  readonly title = '我是只读属性'
  private constructor(name: string, age: number) {
    super(name, age)
    console.log(this.gender)
  }

  // 静态修饰符
  static create(name: string, age: number) {
    return new Student(name, age)
  }
}

const person = new Person('jack', 122)
// person.gender

// const jack = Student.create('joe', 20)
const jack = Student.create('joe', 20)
jack.title

// ----------类和接口  implements----------------
interface Run {
  run: (a: string, b: number) => void
}

class Each implements Run {
  run() {}
}
const run = new Each()
run.run()

// ----------抽象类----------------
// 只能被继承，不能创建类
// 抽象修饰符 abstract
abstract class Animal {
  eat(food: string): void {
    console.log(`呼噜噜的吃：${food}`)
  }

  abstract run(a: string): void
}

class Hello extends Animal {
  run(name: string): void {
    console.log(name)
  }
}

const animal = new Hello()
animal.run('joe')

// ----------泛型----------------

function createArray<T>(length: number, value: T): T[] {
  const arr = Array<T>(length).fill(value)
  return arr
}

const arrs = createArray(3, number)
